package com.yunhe.policyfulfillment.policyful.controller;

import com.yunhe.common.model.ResultObject;
import com.yunhe.common.model.mybatis.PageResult;
import com.yunhe.policyfulfillment.authority.domain.PolicyOrg;
import com.yunhe.policyfulfillment.authority.service.IPolicyOrgService;
import com.yunhe.policyfulfillment.policyful.domain.*;
import com.yunhe.policyfulfillment.policyful.model.*;
import com.yunhe.policyfulfillment.policyful.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.List;

/**
 * @ClassName PortalController
 * @Description TODO
 * @Author HeTao
 * @Date 2021/7/26 9:51
 * @Version 1.0
 **/
@RestController
@RequestMapping(value = "/portal")
@Api(value = "Portal", description = "门户接口", tags = {"门户接口"})
public class PortalController {

    @Autowired
    private IPolicyOrgService policyOrgService;

    @Autowired
    private AppealService appealService;

    @Autowired
    private AppealSatisfactionService appealSatisfactionService;

    @Autowired
    private PolicyCommonQuestionService policyCommonQuestionService;

    /**
     * 查询所有组织
     * @author hetao
     * @date 2021/07/22
     **/
    @ApiOperation("查询所有组织")
    @GetMapping(value = "/findPolicyOrgs")
    public ResponseEntity<ResultObject<List<PolicyOrg>>> findPolicyOrgs(){
        return new ResponseEntity<>(new ResultObject(policyOrgService.findPolicyOrgs()), HttpStatus.OK);
    }

    @ApiOperation("获取诉求统计量")
    @GetMapping(value = "/getAppealStatistic")
    public ResponseEntity<ResultObject<AppealStatistic>> getAppealStatistic() throws ParseException {
        AppealStatistic result = appealService.getAppealStatistic();
        return new ResponseEntity<>(new ResultObject(result), HttpStatus.OK);
    }

    @ApiOperation("根据条件查询诉求（门户）")
    @PostMapping("/getAppealByConditionPortal")
    public ResponseEntity<ResultObject<List<Appeal>>> getAppealByConditionPortal(@RequestBody AppealCondition appealCondition) throws ParseException {
        PageResult result = appealService.getAppealByConditionPortal(appealCondition);
        return new ResponseEntity<>(new ResultObject(result),HttpStatus.OK);
    }

    @ApiOperation("根据组织类型查询组织")
    @GetMapping(value = "/findPolicyOrgsByOrgType")
    public ResponseEntity<ResultObject<List<PolicyOrg>>> findPolicyOrgsByOrgType(@RequestParam(value = "orgType",required = true) String orgType){
        return new ResponseEntity<>(new ResultObject(policyOrgService.findPolicyOrgsByOrgType(orgType)), HttpStatus.OK);
    }

    @ApiOperation("首页诉求满意度统计")
    @GetMapping(value = "/indexAppealSatisfactionStatistics")
    public ResponseEntity<ResultObject<IndexSatisfactionStatistics>> indexAppealSatisfactionStatistics(){
        return new ResponseEntity<>(new ResultObject(appealSatisfactionService.indexAppealSatisfactionStatistics()), HttpStatus.OK);
    }

    /**
     * 首页常见问题
     * 根据条件查询列表
     * @author zb
     * @date 2021/10/12
     **/
    @ApiOperation("首页常见问题")
    @PostMapping("/findPolicyCommonQuestionList")
    public ResponseEntity<ResultObject<PageResult<PolicyCommonQuestion>>> findPolicyCommonQuestionListByCondition(@RequestBody PolicyCommonQuestionVo vo) {
        vo.setState("1");
        return new ResponseEntity<>(new ResultObject(policyCommonQuestionService.findPolicyCommonQuestionListByCondition(vo)), HttpStatus.OK);
    }

    /**
     * 首页常见问题
     * 查询 根据主键 id 查询
     * @author zb
     * @date 2021/10/12
     **/
    @ApiOperation("首页根据id查询常见问题")
    @GetMapping("/findPolicyCommonQuestionById")
    public ResponseEntity<ResultObject<PolicyCommonQuestion>> findPolicyCommonQuestionById(@RequestParam(value = "id", required = true) Long id) {
        return new ResponseEntity<>(new ResultObject(policyCommonQuestionService.findPolicyCommonQuestionByIdForIndex(id)), HttpStatus.OK);
    }
}
